package win.zxshuo.www.model.chapters;

import javax.persistence.*;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Date;

@Entity
@Table(name = "chapter10",indexes = {
        @Index(name = "bookid_index",columnList = "bookId",unique = false),
        @Index(name = "title_index",columnList = "title",unique = false),
        @Index(name = "spider_url_inde",columnList = "spiderUrl",unique = false)
})
public class Chapter10Model  implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "createDate",updatable = false)
    private Date createDate;

    @Column(name = "modifyDate")
    private Date modifyDate;

    @Column(name = "bookId")
    private Long bookId;

    private String title;

    @Column(columnDefinition="LONGTEXT")
    private String content;

    private String spiderUrl;

    private String spiderStatus; // 0 伪爬行 1已爬行，爬行失败

    private Integer chapterWordNum;

    // 构造器用来快速构建实体类，没办法只能这么写了，又不想用nosql
    public Chapter10Model(ChapterModel chapterModel){
        if (chapterModel.getId() != null){
            setId(chapterModel.getId());
        }
        setCreateDate(chapterModel.getCreateDate());
        setModifyDate(chapterModel.getModifyDate());
        setBookId(chapterModel.getBookId());
        setTitle(chapterModel.getTitle());
        setContent(chapterModel.getContent());
        setSpiderUrl(chapterModel.getSpiderUrl());
        setSpiderStatus(chapterModel.getSpiderStatus());
        setChapterWordNum(chapterModel.getChapterWordNum());
    }

    public Chapter10Model(){

    }

    public Chapter10Model(Object unknownObj,Class tClass) throws Exception{

        Method mGetId = tClass.getMethod("getId");
        Long id = (Long) mGetId.invoke(unknownObj);
        setId(id);

        Method mGetCreateDate = tClass.getMethod("getCreateDate");
        Date createDate = (Date) mGetCreateDate.invoke(unknownObj);
        setCreateDate(createDate);

        Method mGetModifyDate = tClass.getMethod("getModifyDate");
        Date modifyDate = (Date) mGetModifyDate.invoke(unknownObj);
        setModifyDate(modifyDate);

        Method mGetBookId = tClass.getMethod("getBookId");
        Long bookid = (Long) mGetBookId.invoke(unknownObj);
        setBookId(bookid);

        Method mGetTitle = tClass.getMethod("getTitle");
        String title = (String) mGetTitle.invoke(unknownObj);
        setTitle(title);

        Method mGetContent = tClass.getMethod("getContent");
        String content = (String) mGetContent.invoke(unknownObj);
        setContent(content);

        Method mGetSpiderUrl = tClass.getMethod("getSpiderUrl");
        String spiderUrl = (String) mGetSpiderUrl.invoke(unknownObj);
        setSpiderUrl(spiderUrl);

        Method mGetSpiderStatus = tClass.getMethod("getSpiderStatus");
        String spiderStatus = (String) mGetSpiderStatus.invoke(unknownObj);
        setSpiderStatus(spiderStatus);

        Method mGetChapterWordNum = tClass.getMethod("getChapterWordNum");
        Integer chapterNum = (Integer) mGetChapterWordNum.invoke(unknownObj);
        setChapterWordNum(chapterNum);

    }

    public Integer getChapterWordNum() {
        return chapterWordNum;
    }

    public void setChapterWordNum(Integer chapterWordNum) {
        this.chapterWordNum = chapterWordNum;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    public Long getBookId() {
        return bookId;
    }

    public void setBookId(Long bookId) {
        this.bookId = bookId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSpiderUrl() {
        return spiderUrl;
    }

    public void setSpiderUrl(String spiderUrl) {
        this.spiderUrl = spiderUrl;
    }

    public String getSpiderStatus() {
        return spiderStatus;
    }

    public void setSpiderStatus(String spiderStatus) {
        this.spiderStatus = spiderStatus;
    }
}
